<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <!--
    Customize this policy to fit your own app's needs. For more guidance, see:
        https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
    Some notes:
        * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
        * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
        * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
            * Enable inline JS: add 'unsafe-inline' to default-src
    -->
    <!-- by wzh 20161223 去掉这个 Security,该用我自己定义的 Security
    <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
    -->

    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="viewport"
          content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">

    <!-- add by wzh 20161223 -->
    <meta http-equiv="Content-Security-Policy"
          content="script-src * ‘unsafe-eval‘; connect-src * ‘unsafe-eval‘;
    object-src ‘self‘; style-src * ‘unsafe-inline‘; img-src *">
    <!-- add by wzh 20161223 -->
    <meta http-equiv="Access-Control-Allow-Origin" content="*"/>

    <link rel="stylesheet" type="text/css" href="css/index.css">
    <title>Cordova Demo 20170109</title>

    <style>
        @media (max-width: 640px) {
            .container {
                width: 100%;
                font-size: 14px;
                /* padding-top: 44px;*/
            }
        }

        @media (min-width: 640px) {
            .container {
                width: 640px;
                margin: 0 auto;
                font-size: 16px;
                /* padding-top: 44px;*/
            }
        }

        .Ul_list {
            height: 300px;
            overflow: auto;
        }

        .Ul_list li {
            height: 45px;
            line-height: 45px;
            padding: 0;
            border-bottom: 1px solid #eee;
            text-align: center;
            background: #fff;
        }

        .tcSure {
            position: absolute;
            bottom: 10px;
            left: 20%;
            background-color: #f60;
            color: white;
            padding: 8px 25px;
            border-radius: 8px;
        }

        .tcCancel {
            position: absolute;
            bottom: 10px;
            right: 20%;
            background-color: #eee;
            color: white;
            padding: 8px 25px;
            border-radius: 8px;
        }

        .logo {
            width: 40%;
            height: auto;
            margin: 0 auto 10px;
        }
    </style>
</head>
<body>
<!--
<div class="app">
-->


<div style="padding: 40px 20px">
    <h1>Apache Cordova Demo </h1>
    <div id="deviceready" class="blink">
        <p class="event listening">Connecting to Device 111 </p>
        <p class="event received">Device is Ready 222 </p>
    </div>

    <ol class="">

        <li class="android-Ios-Setting" onclick="exitApp()" style="color: crimson ; padding-left: 10px;margin: 10px 0">
            退出 App
        </li>

        <li id="appVersion" style="padding-left: 10px;margin: 10px 0">
            版本信息：V1.0.17012301222
        </li>
        <li onclick="checkUpdate()" style="padding-left: 10px;margin: 10px 0">
            软件更新
        </li>
        <li onclick="updateApp.about()" style="padding-left: 10px;margin: 10px 0">
            关于
        </li>
        <li class="android-Ios-Setting" onclick="openSetting('network')" style="padding-left: 10px;margin: 10px 0">
            打开网络权限设置
        </li>
        <li class="android-Ios-Setting" onclick="openSetting('wifi')" style="padding-left: 10px;margin: 10px 0">
            打开 WIFI 权限设置
        </li>
        <li class="android-Setting" onclick="openSetting('application')" style="padding-left: 10px;margin: 10px 0">
            打开 App 权限设置
        </li>
        <li class="android-Setting" onclick="openSetting('application_details')"
            style="padding-left: 10px;margin: 10px 0">
            打开 本程序 权限设置
        </li>
        <li class="android-Setting" onclick="openSetting('application_development')"
            style="padding-left: 10px;margin: 10px 0">
            打开 开发选项 权限设置
        </li>
        <li class="android-Setting" onclick="openSetting('storage')" style="padding-left: 10px;margin: 10px 0">
            打开 storage 设置
        </li>
        <li class="ios-Setting" onclick="store('application_development')" style="padding-left: 10px;margin: 10px 0">
            打开 store 设置
        </li>
        <li class="ios-Setting" onclick="store('about')" style="padding-left: 10px;margin: 10px 0">
            打开 about 设置
        </li>


        <li id="requestApplicationUpdate"
            style="color: #b70404;padding-left: 10px;margin: 10px 0">
            发送检查更新请求
        </li>

        <li id="isUpdateAvailableForInstallation"
            style="color: #b70404;padding-left: 10px;margin: 10px 0">
             检查更新存在否？
        </li>

        <li id="fetchUpdate"  style="color: #b70404;padding-left: 10px;margin: 10px 0">
            获取更新
        </li>

        <li id="getVersionInfo"  style="color: #b70404;padding-left: 10px;margin: 10px 0">
             获取版本号
        </li>

        <li id="installUpdate"  style="color: #b70404;padding-left: 10px;margin: 10px 0">
            安装更新
        </li>


    </ol>
</div>
<!-- 以下是支持的 setting
"about", // ios
"accessibility", // ios, android
"account", // ios, android
"airplane_mode", // ios, android
"apn", // android
"application_details", // ios, android
"application_development", // android
"application", // android
"autolock", // ios
"bluetooth", // ios, android
"castle", // ios
"captioning", // android
"cast", // android
"cellular_usage", // ios
"configuration_list", // ios
"data_roaming", // android
"date", // ios, android
"display", // ios, android
"dream", // android
"facetime", // ios
"home", // android
"keyboard", // ios, android
"keyboard_subtype", // android
"locale", // ios, android
"location", // ios, android
"manage_all_applications", // android
"manage_applications", // android
"memory_card", // android
"music", // ios
"music_equalizer", // ios
"music_volume", // ios
"network", // ios, android
"nike_ipod", // ios
"nfcsharing", // android
"nfc_payment", // android
"nfc_settings", // android
"notes", // ios
"notification_id", // ios
"passbook", // ios
"phone", // ios
"photos", // ios
"print", // android
"privacy", // android
"quick_launch", // android
"reset", // ios
"ringtone", // ios
"browser", // ios
"search", // ios, android
"security", // android
"settings", // ios, android
"show_regulatory_info",
"sound", // ios, android
"software_update", // ios
"storage", // ios, android
"store", // ios, android
"sync", // android
"tethering", // ios
"twitter", // ios
"usage", // ios, android
"user_dictionary", // android
"video", // ios
"voice_input", // android
"vpn", // ios
"wallpaper", // ios
"wifi_ip", // android
"wifi", // ios, android
"wireless" // android
-->

<script type="text/javascript" src="cordova.js"></script>
<!-- by wzh 20161223 想不起来什么地方需要jquery了 -->
<script type="text/javascript" src="js/lib/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/lib/updataApp.js"></script>
<!-- by wzh 20161223 index.js 放在 updateApp.js 后面 -->

<script type="text/javascript" src="js/index.js"></script>

<script>
    checkUpdate = function () {
        succCallbackl = function (res) {
            if (res == "IOS") {
                //alert("IOS app 升级");
                //var url_IOS = "http://m.dhbm.cn/app/qy/lmsd/ios/"; //可以从服务端获取更新APP的路径
                var url_IOS = "http://m.dhbm.cn/app/qy/yltt/ios/"; //可以从服务端获取更新APP的路径
                //window.open(url_IOS, '_system', 'location=yes');
                window.open(url_IOS, '_target');
            } else {
                console.log('succCallbackl 下载成功！' + res);
                //config 首页 去掉了 index.html，不用再跳转了
                // window.location.href = 'Home_yltt_index.html';
            }

        };
        errorCallback = function (res) {
            console.log('errorCallback 下载失败！' + res);
            //config 首页 去掉了 index.html，不用再跳转了
            // window.location.href = 'Home_yltt_index.html';
        };

        //add by wzh 20161223 重新测试 app 升级
        //var apkUrl = "http://api2.dhbm.cn/wap/GetVersionAppH5/?key=3414d916c27e14bc3e9e08a30660d5ec268e76d009aee2a2c5a828973f40d223&appid=8880018&flag=com.dhbm.lmsd&encoding=utf-8&resulttype=json";
        var apkUrl_APK = "http://api2.dhbm.cn:8080/getApkVersion.php?who=yltt_apk";
        var apkUrl_IPA = "http://api2.dhbm.cn:8080/getApkVersion.php?who=yltt_ipa";
        var apkUrl = "";
        //样本 : {"apk":"http://m.dhbm.cn/app/qy/lmsd/an/dhbm.lmsd.1.0.160707.apk","version":"1.0","sub":"160707"}

        var u = navigator.userAgent;
        var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
        //console.log("这是 ios 吗? =====" + isiOS);
        //alert('是否是iOS：'+isiOS);
        if (isiOS) {
            apkUrl = apkUrl_IPA;
        }
        else {
            //这是 android ，其他平台先忽略
            apkUrl = apkUrl_APK;
        }

        setTimeout(updateApp.checkUpdate(apkUrl, succCallbackl, errorCallback), 500);
    };

    openSetting = function (setting) {
        if (window.cordova && window.cordova.plugins.settings) {
            console.log('openNativeSettingsTest is active');
            window.cordova.plugins.settings.open(setting, function () {
                        console.log('opened settings');
                    },
                    function () {
                        console.log('failed to open settings');
                    }
            );
        } else {
            console.log('openNativeSettingsTest is not active!');
        }
    };





</script>
</body>
</html>
